package com.tledu.instrument.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.instrument.domain.InstrumentInfo;
import com.tledu.instrument.service.IInstrumentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 仪器信息Controller
 * 
 * @author longxf
 * @date 2024-08-28
 */
@RestController
@RequestMapping("/instrument/info")
public class InstrumentInfoController extends BaseController
{
    @Autowired
    private IInstrumentInfoService instrumentInfoService;

    /**
     * 查询仪器信息列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(InstrumentInfo instrumentInfo)
    {
        startPage();
        List<InstrumentInfo> list = instrumentInfoService.selectInstrumentInfoList(instrumentInfo);
        return getDataTable(list);
    }

    /**
     * 导出仪器信息列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:info:export')")
    @Log(title = "仪器信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InstrumentInfo instrumentInfo)
    {
        List<InstrumentInfo> list = instrumentInfoService.selectInstrumentInfoList(instrumentInfo);
        ExcelUtil<InstrumentInfo> util = new ExcelUtil<InstrumentInfo>(InstrumentInfo.class);
        util.exportExcel(response, list, "仪器信息数据");
    }

    /**
     * 获取仪器信息详细信息
     */
    //查看按钮
    @PreAuthorize("@ss.hasPermi('instrument:info:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return success(instrumentInfoService.selectInstrumentInfoById(id));
    }

    /**
     * 新增仪器信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:info:add')")
    @Log(title = "仪器信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InstrumentInfo instrumentInfo)
    {
        return toAjax(instrumentInfoService.insertInstrumentInfo(instrumentInfo));
    }

    /**
     * 修改仪器信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:info:edit')")
    @Log(title = "仪器信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InstrumentInfo instrumentInfo)
    {
        return toAjax(instrumentInfoService.updateInstrumentInfo(instrumentInfo));
    }


    // 逻辑删除信息
    @PreAuthorize("@ss.hasPermi('instrument:info:remove')")
    @Log(title = "仪器信息", businessType = BusinessType.UPDATE)
    @PutMapping("/logic")
    public AjaxResult dlelogic(@RequestBody InstrumentInfo instrumentInfo) {
        return toAjax(instrumentInfoService.updateShow(instrumentInfo));
    }

    /**
     * 删除仪器信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:info:remove')")
    @Log(title = "仪器信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(instrumentInfoService.deleteInstrumentInfoByIds(ids));
    }
}
